<?php

class Core_Table_Model_Mail extends Database_Table_Row
{

	/**
	 * @return int
	 */
	public function getId()
	{
		return $this -> template_id;
	}
	
	/**
	 * @return string
	 */
	public function getTitle()
	{
		return $this->template_key;
	}

	/**
	 * @return string
	 */
	public function getName()
	{
		return $this -> template_key;
	}

	/**
	 * @return Mail_Table_Model_Translation
	 */
	public function getTranslation($lang, $alternate = TRUE)
	{
		$table = Nuo::getTable('core/mail/translation');

		$select = $table -> select() -> where('template_id=?', $this -> getId()) -> where('lang_id=?', $lang);
		
		$item = $table -> fetchRow($select);

		if (!$item && $alternate)
		{
			$select = $table -> select() -> where('template_id=?', $this -> getId());
			$item = $table -> fetchRow($select);
		}

		return $item;
	}

}
